﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SyncLib
{
    public class CommonVariable
    {
        static Dictionary<string, object> _DicValue;
        private const string SqlConnKey = "SqlConnKey";
        private const string SyncConfigSchemaKey="SyncConfigSchema";
        private const string FolderBatch = "FolderBatch";
        private const string AppLocationKey = "AppLocation";
        private const string CleanBatchKey = "CleanBatch";
        static CommonVariable()
        {
            _DicValue = new Dictionary<string, object>();
        }
        public static void Add(string key, object value)
        {
            _DicValue[key] = value;
        }
        public static object Get(string key)
        {
            if (_DicValue.ContainsKey(key))
                return _DicValue[key];
            return null;
        }
        public static string SqlConnectionString
        {
            get
            {
                if (_DicValue.ContainsKey(SqlConnKey))
                    return _DicValue[SqlConnKey].ToString();
                else
                    return Properties.Settings.Default.SqlConnectionString;
            }
            set
            {
                _DicValue[SqlConnKey] = value;
            }
        }
        public static string SyncConfigSchema
        {
            get
            {
                if (_DicValue.ContainsKey(SyncConfigSchemaKey))
                    return _DicValue[SyncConfigSchemaKey].ToString();
                else
                    return "dbo";

            }
            set
            {
                _DicValue[SyncConfigSchemaKey] = value;
            }
        }
        public static string SyncFolderBatch{
            get{return _DicValue[FolderBatch].ToString();}
            set{_DicValue[FolderBatch]=value;}
        }
        public static AppLocation AppLocation
        {
            get
            {
                if (_DicValue.ContainsKey(AppLocationKey))
                    return (AppLocation)_DicValue[AppLocationKey];
                else
                    throw new Exception("AppLocation not defined");
            }
            set
            {
                _DicValue[AppLocationKey] = value;
            }
        }
        public static bool CleanBatch
        {
            get
            {
                if (_DicValue.ContainsKey(CleanBatchKey))
                    return (bool)_DicValue[CleanBatchKey];
                else
                    return false;
            }
            set
            {
                _DicValue[CleanBatchKey] = value;
            }
        }

    }

    public enum AppLocation
    {
        Server = 0,
        Client = 1,
        Undefine = -1
    }
}
